// NPC Manager with Respawn System
#pragma once
#include "NPC.h"
#include "NPCGroup.h"
#include <vector>

struct SpawnPoint
{
    D3DXVECTOR3 position;
    float respawnTime;
    float currentTime;
    NPC* assignedNPC;

    SpawnPoint(const D3DXVECTOR3& pos, float respawn = 10.0f)
        : position(pos), respawnTime(respawn), currentTime(0.0f), assignedNPC(NULL) {}
};

class NPCManager
{
public:
    NPCManager();
    ~NPCManager();

    bool Initialize(LPDIRECT3DDEVICE9 device, int maxNPCs, class Terrain* terrain);
    void Update(float deltaTime, GameObject* playerTarget, const std::vector<GameObject*>& obstacles);
    void RenderAll(LPDIRECT3DDEVICE9 device);
    void Cleanup();

    // Respawn management
    void AddSpawnPoint(const D3DXVECTOR3& position, float respawnTime = 10.0f);
    void CheckRespawns(float deltaTime);

    // Group management
    void CreateGroups(int groupCount);
    std::vector<NPCGroup*>& GetGroups() { return m_groups; }

    // Access
    std::vector<NPC*>& GetNPCs() { return m_npcs; }
    int GetAliveNPCCount() const;

private:
    void RespawnNPC(SpawnPoint& sp);

    LPDIRECT3DDEVICE9 m_pDevice;
    class Terrain* m_pTerrain;
    std::vector<NPC*> m_npcs;
    std::vector<SpawnPoint> m_spawnPoints;
    std::vector<NPCGroup*> m_groups;

    int m_maxNPCs;
};
